package usefunction;

import java.util.stream.Stream;

/**
 * @author: fqtang
 * @date: 2024/12/15/6:41
 * @description: 函数引用
 */
public class FunctionRef {

	public static void main(String[] args) {
		Stream.of(
				new Student("张三", 11),
				new Student("李四", 16),
				new Student("王麻子", 26),
				new Student("王五", 21)
			)
//			.filter(stu->stu.age()>16) //lambda表达式方法引用
			//.filter(FunctionRef::getStuAge) //静态方法引用
			.filter(stu -> stu.queryStuAge(stu)) //非静态方法引用
			//.forEach(stu->System.out.println(stu.name()));
//			.forEach(FunctionRef::abc); //静态方法引用
			.forEach(student -> student.print(student));//非静态方法引用
	}

	public static void abc(Student stu) {
		System.out.println(stu);
	}

	public static boolean getStuAge(Student stu) {
		return stu.age() > 16;
	}

	record Student(String name, int age) {
		public void print(Student stu) {
			System.out.println(stu);
		}
		/*
		Student::print
		(stu)->stu.print(stu)
		 */

		public boolean queryStuAge(Student stu) {
			return stu.age() > 16;
		}
	}
}

